
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }

public class Solution {
    int count = 0;
    public int getLeafNodeCount(TreeNode root) {
        //1、遍历思路
//        if(root == null){
//            return 0;
//        }
//        if(root.left == null && root.right == null){
//            count++;
//        }
//        getLeafNodeCount(root.left);
//        getLeafNodeCount(root.right);
//        return count;

        //2、子问题思路
        if(root == null){
            return 0;
        }
        if(root.left == null && root.right == null){
            return 1;
        }
        return getLeafNodeCount(root.left)+getLeafNodeCount(root.right);
    }
}


